home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / hardware / rap / record.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.7 KB  |  118 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include <fcntl.h>
  19. #include <string.h>
  20. #include <errno.h>
  21. #include <sys/types.h>
  22. #include <signal.h>
  23.  
  24. /*    
  25.  *    record.c
  26.  *
  27.  *    This program records a song from a CD by using RAP-10 board
  28.  *
  29.  */
  30.  
  31. #define    BUF_SIZE    4096
  32. #define    FILE_HDR    "RAP-10 WAVE FILE"
  33. #define    RAP_FILE    "/dev/rap"
  34. #define    MAX_BUF     10 
  35.  
  36. uchar_t    buf[BUF_SIZE];
  37. uchar_t    *fname;
  38. int       done;
  39. void       endProg( int );
  40.  
  41. main (int argc, char **argv)
  42. {
  43.  
  44.     register int    fd, rapfd, bytes, i;
  45.  
  46.     if ( argc <= 1 ) {
  47.         printf ("record: Usage: record <file_name>\n");
  48.         exit(0);
  49.     }
  50.  
  51.     fname = argv[1];
  52.         printf ("record: opening file %s\n", fname); 
  53.         fd = open (fname, O_WRONLY | O_CREAT, 0777);
  54.         if ( fd == -1 ) {
  55.                 printf ("record: Cannot create file, errno = %d\n", errno);
  56.                 close(rapfd);
  57.                 exit(0);
  58.         }
  59.  
  60.     printf ("record: opening RAP card\n");
  61.     rapfd = open (RAP_FILE, O_RDONLY);
  62.     if ( rapfd <= 0 ) {
  63.         printf ("record: Cannot open RAP card, errno = %d\n",
  64.         errno);
  65.         exit(0);
  66.     }
  67.  
  68.     printf ("record: Writing RAP-10 file ID\n");
  69.     if ( write(fd, FILE_HDR, strlen(FILE_HDR)) <= 0 ) {
  70.         printf ("record: Could not write the file ID, errno = %d\n",
  71.         errno);
  72.         close(rapfd);
  73.         close(fd);
  74.         exit(0);
  75.     }
  76.  
  77.  
  78.     printf ("record: Rcording music ..Ctrl-C to stop\n");
  79.  
  80.     done = 0;
  81.     sigset (SIGINT, endProg);
  82.  
  83.     /* for ( i = 0; i < 10; i++ ) {  */
  84.     while ( !done ) {  
  85.         bytes = read(rapfd, buf, BUF_SIZE);
  86.         if ( bytes <= 0 ) {
  87.             printf ("record: Cannot read from RAP, errno = %d\n",
  88.             errno);
  89.             close (rapfd);
  90.             close (fd);
  91.             exit(0);
  92.         }
  93.  
  94.         if ( write (fd, buf, bytes) <= 0 ) {
  95.                         printf ("record: error writing to file, errno = %d\n",
  96.                         errno);
  97.                         close (rapfd);
  98.                         close (fd);
  99.                         exit(0);
  100.         }
  101.     }
  102.  
  103.     printf ("record: Song succesfully recorded\n");
  104.     close(rapfd);
  105.     close (fd);
  106.  
  107.     exit(0);
  108. }
  109.  
  110. void
  111. endProg( int s )
  112. {
  113.     printf ("record: signal %d received\n", s);
  114.     done = 1;
  115. }
  116.  
  117.  
  118.